import {postReq,getReq,successStatus} from "@/common/request"
import {uploadFile} from "@/common/utils"


export const getSuccessStatus=()=>successStatus


/**用来测试的请求  */
export const testApi=(msg:string)=>getReq("/admin/user/test",{msg})

/**拉取当前用户信息的请求 */ 
export const getUserInfoApi=()=>postReq("/admin/user/getUserInfo",{},{closeGlobalLoading:true})

/**退出登录的请求 */
export const logoutApi=()=>postReq("/admin/user/logout")

/**获取用户的角色信息，没传用户id则获取当前用户的 */
export const getRolesInfoApi=(userId?:IdType)=>getReq("/admin/user/getRolesInfo",{userId})

/**用户分页查询的请求  */
export const getUserPageApi=(body:PageReqParams<UserType>):Promise<PageResponseData<UserType>>=>postReq("/admin/user/page",body)

/**用户列表查询的请求  */
export const getUserListApi=(body:Partial<UserType>={})=>postReq("/admin/user/list",body)

/**用户列表查询的请求  */
export const getUserDetailApi=(id:IdType)=>getReq("/admin/user/detail",{id})

/**用户新增的请求  */
export const addUserApi=(body:AddOrUpdateReqParams<UserType>[])=>postReq("/admin/user/add",body)

/**用户更新的请求  */
export const updateUserApi=(body:AddOrUpdateReqParams<UserType>[])=>postReq("/admin/user/update",body)

/**用户删除的请求  */
export const deleteUserApi=(body:IdType[])=>postReq("/admin/user/deleteByIds",body)

/**用户头像上传的请求  */
export const uploadAvatarApi=(file:File)=>uploadFile(file,"file","/admin/user/uploadAvatar")

/**用户头像删除的请求*/
export const deleteAvatarApi=(avatarUrls:string[])=>postReq("/admin/user/deleteAvatar",avatarUrls)

/** 为用户分配角色  */
export const giveRolesApi=(body:{userId:IdType,roleIds:IdType[]})=>postReq("/admin/user/giveRoles",body)